package com.yujianweb.oop;
// 测试多态
public class TestPolym {
    public static void main(String[] args) {
        animalCry(new Dog());
        animalCry(new Cat());

        Animal animal = new Dog();  //向上转型（自动）
        animal.shout();
        //animal.seeDoor();
        Dog d = (Dog)animal;    //向下转型（强制）
        d.seeDoor();

        //Cat c = (Cat)animal;  //编译不会报错，运行会报异常：ClassCastException
        if(animal instanceof Cat){
            Cat c = (Cat)animal;
            c.catchMouse();
        }

    }

    static void animalCry(Animal a){
        System.out.println(a);
        a.shout();      //可以出现多态
    }
}
